package com.liyuxiang.yygh.hosp.controller.api;

import com.liyuxiang.yygh.common.result.Result;
import com.liyuxiang.yygh.hosp.service.DepartmentService;
import com.liyuxiang.yygh.hosp.service.HospitalService;
import com.liyuxiang.yygh.hosp.service.HospitalSetService;
import com.liyuxiang.yygh.hosp.service.ScheduleService;
import com.liyuxiang.yygh.model.hosp.Hospital;
import com.liyuxiang.yygh.model.hosp.Schedule;
import com.liyuxiang.yygh.vo.hosp.DepartmentVo;
import com.liyuxiang.yygh.vo.hosp.HospitalQueryVo;
import com.liyuxiang.yygh.vo.hosp.ScheduleOrderVo;
import com.liyuxiang.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {
    @Autowired
    HospitalService hospitalService;
    @Autowired
    DepartmentService departmentService;
    @Autowired
    ScheduleService scheduleService;
    @Autowired
    HospitalSetService hospitalSetService;

    @GetMapping("{page}/{limit}")
    @ApiOperation("查询医院列表")
    public Result findHospitalList(@PathVariable("page") int page, @PathVariable("limit") int limit, HospitalQueryVo hospitalQueryVo) {
        Page<Hospital> hospitalPage = hospitalService.getHospitalPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitalPage);
    }

    @GetMapping("/findByHosname/{hosName}")
    @ApiOperation("根据医院名称查询")
    public Result findByHosname(@PathVariable("hosName") String hosName) {
        List<Hospital> list = hospitalService.getHospitalByHosName(hosName);
        return Result.ok(list);
    }

    @GetMapping("/{hoscode}")
    public Result findHospitalDetails(@PathVariable("hoscode") String hoscode) {
        Hospital hospitalDetails = hospitalService.getHospitalByHoscode(hoscode);
        return Result.ok(hospitalDetails);
    }

    @GetMapping("findByHosName/{hosname}")
    public Result findByHosName(@PathVariable("hosname") String hosname) {
        List<Hospital> list = hospitalService.getHospitalByHosName(hosname);
        return Result.ok(list);
    }

    @GetMapping("/department/{hoscode}")
    public Result findDepartmentByHoscode(@PathVariable("hoscode") String hoscode) {
        List<DepartmentVo> list = departmentService.findDeptTree(hoscode);
        return Result.ok(list);
    }

    //获取可预约排班数据
    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode
    ) {

        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    //获取排班数据
    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate
    ) {

        return Result.ok(scheduleService.getScheduleDetail(hoscode, depcode, workDate));
    }

    @ApiOperation(value = "获取排班id获取排版数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId) {
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId
    ) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@ApiParam(name = "hoscode", value = "医院code", required = true)
                                    @PathVariable("hoscode") String hoscode) {
        return hospitalSetService.getSignInfoVo(hoscode);

    }


}
